package com.ldy.core.common;

import java.util.HashMap;
import java.util.Map;
/**
 * response返回对象
 * @author lindeyi
 *
 */
public class Result {
	String json ="";
	public static final int FAIL = 30000;
	public static final int SUCCESS = 20000;
	public static final int UNLOGIN = 20001;
	private int code;
	
	private Object data;
	
	private String msg;
	
	public static Result success() {
		Result result = new Result();
		result.code = SUCCESS;
		return result;
	}
	public static Result success(Object data) {
		Result result = new Result();
		result.code = SUCCESS;
		result.data = data;
		return result;
	}
	public static Result failure(String msg) {
		Result result = new Result();
		result.code = FAIL;
		result.msg = msg;
		return result;
	}
	public static Result failure(int code , String msg) {
		Result result = new Result();
		result.code = code;
		result.msg = msg;
		return result;
	}
	public Result map(String key, Object val) {
		if (null == this.data) {
			this.data = new HashMap<>();
		}
		@SuppressWarnings("unchecked")
		Map<String, Object> map = (Map<String, Object>) this.data;
		map.put(key, val);
		return this;
	}
	/**
	 * @return the code
	 */
	public int getCode() {
		return code;
	}
	/**
	 * @param code the code to set
	 */
	public void setCode(int code) {
		this.code = code;
	}
	/**
	 * @return the data
	 */
	public Object getData() {
		return data;
	}
	/**
	 * @param data the data to set
	 */
	public void setData(Object data) {
		this.data = data;
	}
	/**
	 * @return the msg
	 */
	public String getMsg() {
		return msg;
	}
	/**
	 * @param msg the msg to set
	 */
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	
}
